Skip to content

Use a GUID for GitHub App webhook delivery IDs - #13

Open
byapparov wants to merge 1 commit into
feat/issue-dependenciesfrom
fix/fork-app-webhook-delivery-guid
Open

byapparov wants to merge 1 commit into
feat/issue-dependenciesfrom
fix/fork-app-webhook-delivery-guid

Conversation

@byapparov

Copy link
Copy Markdown
Member

Summary

App webhook deliveries now send crypto.randomUUID() as X-GitHub-Delivery instead of String(Date.now()), so two deliveries in the same millisecond no longer share an ID (closes #10). This is the same change as the upstream PR vercel-labs#413; the next upstream sync brings it in either way.

aictrl can then remove its build-time patch (scripts/e2e/patch-github-emulator-delivery-id.mjs).

Stacked on #12; retarget after #11 and #12 merge.

Verification

  • New test in webhook-installation.test.ts pins Date.now() and expects two distinct GUIDs. It fails before the change and passes after.
  • In node:24-bookworm-slim, all of these pass: build, type-check, type-check:tsc, lint (0 errors), format, and all package tests (core 113, github 188, github-emulator 6).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Br5cbz3i7Y5PaRdx3DUfXx

App webhook deliveries used Date.now() as X-GitHub-Delivery, so two
deliveries in the same millisecond shared an ID. Receivers that
deduplicate by delivery ID, as GitHub recommends, then dropped the second
event. GitHub sends a GUID; the emulator now does too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Br5cbz3i7Y5PaRdx3DUfXx
"Content-Type": "application/json",
"X-GitHub-Event": event,
"X-GitHub-Delivery": String(Date.now()),
"X-GitHub-Delivery": crypto.randomUUID(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Bare crypto global; import randomUUID instead.

--- a/packages/@emulators/github/src/index.ts
+++ b/packages/@emulators/github/src/index.ts
@@
-import { createHmac, generateKeyPair } from "crypto";
+import { createHmac, generateKeyPair, randomUUID } from "crypto";
@@
-      "X-GitHub-Delivery": crypto.randomUUID(),
+      "X-GitHub-Delivery": randomUUID(),
🤖 Fix with your agent
Fix this code review finding (aictrl-dev/github-emulator PR #13, packages/@emulators/github/src/index.ts:634):

Problem: Bare crypto global; import randomUUID instead
Detail: The new code calls `crypto.randomUUID()` via the ambient WebCrypto global, but this file already imports its crypto primitives by name (`import { createHmac, generateKeyPair } from "crypto"`, line 1). The bare `crypto` identifier is never imported, so the module only compiles/runs where the global exists: the WebCrypto global is only available by default on Node >= 19 (Node 18 needs --experimental-global-webcrypto) and `tsc` only resolves it with recent @types/node. The surrounding code establishes at most a Node 18+ baseline (it uses global `fetch` / `AbortSignal.timeout`), so on Node 18 runtimes every app-webhook dispatch in `deliverToAppWebhookUrls` would throw a ReferenceError, and even where it works the implicit global is inconsistent with the file's own named-import convention. Use the named export from the module already imported.
Suggested fix: Extend the existing import on line 1 and call it directly: `import { createHmac, generateKeyPair, randomUUID } from "crypto";` then `"X-GitHub-Delivery": randomUUID(),`.

Suggested patch:
--- a/packages/@emulators/github/src/index.ts
+++ b/packages/@emulators/github/src/index.ts
@@
-import { createHmac, generateKeyPair } from "crypto";
+import { createHmac, generateKeyPair, randomUUID } from "crypto";
@@
-      "X-GitHub-Delivery": crypto.randomUUID(),
+      "X-GitHub-Delivery": randomUUID(),

Implement the fix on the PR head branch and add a regression test that fails before the fix and passes after.
Why this matters

The new code calls crypto.randomUUID() via the ambient WebCrypto global, but this file already imports its crypto primitives by name (import { createHmac, generateKeyPair } from "crypto", line 1). The bare crypto identifier is never imported, so the module only compiles/runs where the global exists: the WebCrypto global is only available by default on Node >= 19 (Node 18 needs --experimental-global-webcrypto) and tsc only resolves it with recent @types/node. The surrounding code establishes at most a Node 18+ baseline (it uses global fetch / AbortSignal.timeout), so on Node 18 runtimes every app-webhook dispatch in deliverToAppWebhookUrls would throw a ReferenceError, and even where it works the implicit global is inconsistent with the file's own named-import convention. Use the named export from the module already imported.

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      "X-GitHub-Event": event,
      "X-GitHub-Delivery": crypto.randomUUID(),
    };
    if (ghApp.webhook_secret) {
      const hmac = createHmac("sha256", ghApp.webhook_secret).update(body).digest("hex");

@aictrl-dev

aictrl-dev Bot commented Nov 17, 2026

Copy link
Copy Markdown

Code review

Verdict: Address the major findings before merging. · 🔴 0 · 🟠 1 · 🟡 0 · ⚪ 0 · 0/1 resolved

  • 🟠 packages/@emulators/github/src/index.ts:634 — Bare crypto global; import randomUUID instead
🤖 Fix all 1 open findings with your agent
Fix the following code review findings on aictrl-dev/github-emulator PR #13 (head branch).
Run the relevant tests/linters after each change.

1. packages/@emulators/github/src/index.ts:634 — Bare crypto global; import randomUUID instead
   Detail: The new code calls `crypto.randomUUID()` via the ambient WebCrypto global, but this file already imports its crypto primitives by name (`import { createHmac, generateKeyPair } from "crypto"`, line 1). The bare `crypto` identifier is never imported, so the module only compiles/runs where the global exists: the WebCrypto global is only available by default on Node >= 19 (Node 18 needs --experimental-global-webcrypto) and `tsc` only resolves it with recent @types/node. The surrounding code establishes at most a Node 18+ baseline (it uses global `fetch` / `AbortSignal.timeout`), so on Node 18 runtimes every app-webhook dispatch in `deliverToAppWebhookUrls` would throw a ReferenceError, and even where it works the implicit global is inconsistent with the file's own named-import convention. Use the named export from the module already imported.
   Suggested fix: Extend the existing import on line 1 and call it directly: `import { createHmac, generateKeyPair, randomUUID } from "crypto";` then `"X-GitHub-Delivery": randomUUID(),`.
📋 Out-of-diff findings (1)
Sev Location Finding
🟠 packages/@emulators/github/src/index.ts:634 Bare crypto global; import randomUUID instead

Reviewed 2 files · 0 inline · view all 1 findings ↗ · AI-generated — verify findings before acting · AI guidance and feedback


aictrl · AI code review for fast-moving teams · aictrl.dev

byapparov added a commit that referenced this pull request Nov 17, 2026
Dependencies (#12):
- issue_dependencies_summary counts only related issues every reader of
  the issue can see (same repository or public), so the shared issue
  payload no longer reveals blockers in private repositories.
- DELETE needs write on the blocked issue only, so an edge whose far end
  became unreadable can still be removed; a malformed id returns 400.
- One findIssueForRepo helper for issue and dependency routes.

Delivery IDs (#13): import randomUUID by name.

Issue types (#14): formatIssueType lives in helpers.ts beside the issue
serializer; a null issue_types seed means the defaults; the type
resolver returns number | null.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Br5cbz3i7Y5PaRdx3DUfXx
@byapparov

Copy link
Copy Markdown
Member Author

Review response — PR 13

Fixes are in 2ca62e2 on the top of the stack (PR 14, feat/issue-types); this stack merges together, so the lower PRs were not rewritten. aictrl-dev/aictrl#7190 pins 2ca62e2.

Issues addressed (pushed to this stack)

  • Bare crypto global; import randomUUID instead — packages/@emulators/github/src/index.ts: The fork imports randomUUID by name. The upstream PR keeps the global so its old base does not conflict on the import line. (commit 2ca62e2)

Review claims verified false (no change needed)

None.

Not addressed here

None.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant